LA County

Row

Row

Row

Mon Apr 13, 2020

10047

360
---
title: "COVID-19 in LAC"
output: 
  flexdashboard::flex_dashboard:
    logo: rbmv_curve.png 
    orientation: rows
    source_code: embed
    theme: flatly
---

 

```{r setup, include=FALSE}
library(flexdashboard)
```

```{r, include=FALSE}
library(tidyverse)
library(lubridate)
library(rvest)
library(sf)
library(leaflet)
library(plotly)
library(rbmv)

`%<>%` <- magrittr::`%<>%`

dph_covid19_page <- read_html("http://www.publichealth.lacounty.gov/media/Coronavirus/locations.htm")

dph_covid19_tbls <- dph_covid19_page %>%
  html_nodes("table") %>%
  html_table()

dph_covid19_messy <- dph_covid19_tbls[[1]] %>%
  repair_names() %>%
  janitor::clean_names() %>%
  rename(locations = x1, total_cases = x2) %>%
  select(-x3)

dph_covid19_totals <- dph_covid19_messy %>%
  slice(2:11)
  
dph_covid19_age_groups <- dph_covid19_messy %>%
  slice(14:18) %>%
  rename(age_group = locations) %>%
  mutate(total_cases = parse_number(total_cases))

dph_covid19_gender <- dph_covid19_messy %>% slice(20:24) %>%
  rename(gender = locations) %>%
  mutate(total_cases = parse_number(total_cases))

lac_total_cases <- parse_number(dph_covid19_totals$total_cases[[1]])
lac_total_deaths <- parse_number(dph_covid19_totals$total_cases[[6]])

dph_covid19_totals %>%
  mutate(locations = str_remove_all(locations, "- ")) %>%
  filter(locations %in% c("Long Beach", "Pasadena")) %>%
  slice(1:2) %>%
  mutate(locations = str_glue("City of {locations}") %>% parse_character(),
         total_cases = parse_number(total_cases)) -> lb_pass

dph_covid19 <- dph_covid19_messy %>% slice(30:365) %>%
  mutate(
    locations = str_remove_all(locations, regex("\\*")),
    total_cases = parse_number(total_cases, na = "--"),
    locations = case_when(
      str_detect(locations, "San Francisquito") ~ "Unincorporated - San Francisquito Canyon/Bouquet Canyon",
      TRUE ~ locations)) %>%
  filter(!locations == "Los Angeles") %>%
  bind_rows(., lb_pass)

captions <- dph_covid19_page %>% 
  html_nodes("caption") %>%
  html_text()

str_remove_all(captions[1], "\\r|\\n|\\t") %>%
  str_split_fixed(., "\\*", 2) -> page_updated

page_updated <- str_split_fixed(page_updated[1], " ", 4)[4]
page_updated <- str_glue("{page_updated}/20")
page_updated <- parse_date(page_updated, "%m/%d/%y")

# uncomment line below if the 'caption' html is not updated on DPH website
# page_updated <- Sys.Date()

page_updated_string <- str_glue("{wday(page_updated, label = T)} {month(page_updated, label = T)} {day(page_updated)}, {year(page_updated)}")

gis <- st_read(
  dsn = "data/gis/geo_export_871186bb-3266-4a1c-a0f6-8cda86b55d55.shp",
  layer = "geo_export_871186bb-3266-4a1c-a0f6-8cda86b55d55",
  quiet = T
)

gis %<>% st_transform(crs = 4326)

health_profile <- read_csv("data/Los_Angeles_County_City_and_Community_Health_Profiles_2018.csv")

lac_covid19 <- gis %>% 
  left_join(., dph_covid19, by = c("label" = "locations")) %>%
  left_join(., health_profile, by = c("lcity" = "GEONAME")) %>%
  mutate(total_cases = if_else(is.na(total_cases), 0, total_cases))

covid19_time_series_cases <- read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_US.csv")

covid19_time_series_deaths <- read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_US.csv")

covid19_time_series_cases %<>% 
  filter(Admin2 == "Los Angeles") %>%
  gather("date", "cases", 12:ncol(covid19_time_series_cases)) %>%
  select(Admin2, date, cases) %>%
  rename(county = Admin2) %>%
  mutate(date = parse_date(date, "%m/%d/%y"),
         case_type = "New Confirmed Case") %>%
  bind_rows(tribble(~county, ~date, ~cases, ~case_type, "Los Angeles", page_updated, lac_total_cases, "New Confirmed Case")) %>%
  distinct()

covid19_time_series_deaths %<>% 
  filter(Admin2 == "Los Angeles") %>%
  gather("date", "cases", 13:ncol(covid19_time_series_deaths)) %>%
  select(Admin2, date, cases) %>%
  rename(county = Admin2) %>%
  mutate(date = parse_date(date, "%m/%d/%y"),
         case_type = "Death") %>%
  bind_rows(tribble(~county, ~date, ~cases, ~case_type, "Los Angeles", page_updated, lac_total_deaths, "Death")) %>%
  distinct()

covid19_time_series <- bind_rows(covid19_time_series_cases, covid19_time_series_deaths) 

light_blue <- rbmv_pal("main", plotly = T)[1]
ruby <- rbmv_pal("main", plotly = T)[2]
pale_black <- rbmv_pal("main", plotly = T)[5]
```

LA County {data-icon="fa-map"}
=====================================

Row {data-height=505}
-------------------------------------

###

```{r}
bins <- c(0, 20, 40, 65, 95, 120, 150, 180, 200, 240, 280, 300, Inf)

pal <- colorBin(
  palette = rbmv_pal("spectrum", plotly = T), 
  domain = lac_covid19$total_cases, 
  bins = bins)

mapbox <- "https://api.mapbox.com/styles/v1/robertmitchellv/cipr7teic001aekm72dnempan/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1Ijoicm9iZXJ0bWl0Y2hlbGx2IiwiYSI6ImNpcHI2cXFnbTA3MHRmbG5jNWJzMzJtaDQifQ.vtvgLokcc_EJgnWVPL4vXw"

label <- str_glue("{lac_covid19$label}
Total cases: {lac_covid19$total_cases}") %>% lapply(htmltools::HTML) lac_covid19 %>% leaflet() %>% addTiles(mapbox, attribution = paste("Data from Los Angeles County Department of Publich Health COVID-19 location table")) %>% addPolygons( fillColor = ~pal(total_cases), weight = 1.5, fillOpacity = 0.7, smoothFactor = 0.5, color = "white", label = label, labelOptions = labelOptions( style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "15px", direction = "auto")) %>% addLegend( pal = pal, values = ~total_cases, opacity = 0.7, title = NULL, position = "bottomright") %>% setView(-118.2, 34, zoom = 9.5) ``` Row {data-height=320} ------------------------------------- ### ```{r} source <- list( x = 1, y = -0.24, text = "Source: 2019 Novel Coronavirus COVID-19 (2019-nCoV)\nData Repository by Johns Hopkins CSSE", showarrow = F, xref = "paper", yref = "paper", xanchor = "right", yanchor = "auto", xshif = 0, yshift = 0, font = list(size = 9, color = "grey") ) covid19_time_series %>% plot_ly(x = ~date, y = ~cases, color = ~case_type, colors = rbmv_pal(plotly = T), type = "scatter", mode = "lines", hoverinfo = "text", text = ~paste("
Case type: ", case_type, "
Date: ", date, "
Cases: ", cases)) %>% layout(title = "COVID-19 Cases + Deaths", xaxis = list(title = " "), yaxis = list(title = "Log(Cases)\n", type = "log"), legend = list(x = 0.05, y = 0.98), margin = list(b = 50), annotations = source) %>% config(displayModeBar = FALSE) ``` ### ```{r} source <- list( x = 1, y = -0.2, text = "Source: Los Angeles County Department of Public Health", showarrow = F, xref = "paper", yref = "paper", xanchor = "right", yanchor = "auto", xshif = 0, yshift = 0, font = list(size = 9, color = "grey") ) dph_covid19_age_groups %>% plot_ly() %>% add_bars(x = ~age_group, y = ~total_cases, color = I(light_blue), hoverinfo = "text", text = ~paste("
Age Group: ", age_group, "
Cases: ", total_cases)) %>% layout(title = "Age Group of COVID-19 Cases", xaxis = list(title = " "), yaxis = list(title = "Total Cases\n"), annotations = source) %>% config(displayModeBar = FALSE) ``` Row {data-height=175} ------------------------------------- ### ```{r} valueBox(page_updated_string, color = light_blue, icon = "fa-calendar", caption = "Data pulled from both LAC DPH and John Hopkins CSSE") ``` ### ```{r} total_cases <- last(covid19_time_series_cases$cases) valueBox(total_cases, color = ruby, icon = "fa-ambulance", caption = "Total Lab Confirmed COVID-19 Cases in LAC") ``` ### ```{r} total_deaths <- last(covid19_time_series_deaths$cases) valueBox(total_deaths, color = pale_black, icon = "fa-medkit", caption = "Total COVID-19 Related Deaths") ```